%ex4

% a)
  % A - A
  pAA = 0.4^2;
  % A - B
  pAB = (1-0.4)^2;
  % A - C
  pAC = 0.4*(1-0.4);
  % A - D
  pAD = 0.4*(1-0.4);


  % B - A
  pBA = 0;
  % B - B
  pBB = 0;
  % B - C
  pBC = 0;
  % B - D
  pBD = 1;

  % C - A
  pCA = 0;
  % C - B
  pCB = 0;
  % C - C
  pCC = 0;
  % C - D
  pCD = 1;

  % D - A
  pDA = 0.6^2;
  % D - B
  pDB = 0.6*(1-0.6);
  % D - C
  pDC = 0.6*(1-0.6);
  % D - D
  pDD = (1-0.6)^2;


  T = [pAA pBA pCA pDA ; pAB pBB pCB pDB ; pAC pBC pCC pDC ; pAD pBD pCD pDD]

% b)

  %pij(10) -> i = A ; j = B
    
  x0 = [1 ; 0 ; 0 ; 0];
  
  %Queremos o x(10)
  %x(10) = Tx(9) = T(T(x(8)) =  ...  = T^10 x(0)
  
  x10 = T^10*x0;
  
  printf("Probabilidade de , comecando em A, chegar a B apos 10 transicoes= %f\n",x10(2));